﻿using CleanLite.Application.Dto.Sys_Menu;
using CleanLite.Application.Services.Base;
using CleanLite.Domain.Entities;
using CleanLite.Infrastructure.SnowId;
using Mapster;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace CleanLite.Application.Services
{
    public class MenuManagerService(ISnowflakeId snowflakeId) : BaseService<Sys_Menu>
    {
        private readonly ISnowflakeId snowflakeId = snowflakeId;

        /// <summary>
        /// 新增菜单项
        /// </summary>
        /// <returns></returns>
        public async Task<string> AddMenuItemAsync(AddMenuItemDto param)
        {
            var entity = param.Adapt<Sys_Menu>();
            entity.CreatedBy = "1";
            entity.Id = snowflakeId.NextId();
            await Repository.InsertAsync(entity);

            return "操作完成";
        }

        /// <summary>
        /// 查询菜单
        /// </summary>
        /// <returns></returns>
        [AllowAnonymous]
        public async Task<List<MenuItemDto>> GetMenuItemsAsync()
        {
            var entity = await Repository.GetListAsync();
            return entity.Adapt<List<MenuItemDto>>();
        }

        [HttpPost]
        public async Task<bool> DeletedItemsAsync(long[] param)
        {
            return await Repository.DeleteAsync(param);
        }
    }
}